package com.bkhech.spring.domain;

import com.fasterxml.jackson.annotation.JsonView;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author guowm
 * @date 2023/3/20
 */
@Data
public class Student {
    @JsonView(LevelViews.Public.class)
    private String fullName;
    @JsonView(LevelViews.SubPublic.class)
    private float height;
    @JsonView(LevelViews.SubPublic.class)
    private float weight;
    @JsonView(LevelViews.Public.class)
    private int age;
    @JsonView(LevelViews.SubPublic.class)
    private String className;
    /**
     * One to Many Relationship
     */
    @JsonView(LevelViews.GrandPublic.class)
    private List<SubjectScore> scores;
    /**
     * One to One Relationship
     */
    @JsonView(LevelViews.SubPublic.class)
    private School school;

    public static Student createStudent() {
        Student student = new Student();
        student.setAge(15);
        student.setFullName("Mark Dsouza");
        student.setWeight(49);
        student.setHeight(150);
        student.setClassName("VIII");
        student.setSchool(createSchool());
        student.setScores(createSubjectScoreList());
        return student;
    }

    private static School createSchool() {
        School school = new School();
        school.setSchoolName("Indian Public School");
        return school;
    }

    private static List<SubjectScore> createSubjectScoreList() {
        List<SubjectScore> subjectScoreList = new ArrayList<>();
        SubjectScore mathScore = new SubjectScore();
        mathScore.setScore(80);
        mathScore.setSubject("Math");
        mathScore.setTeacher("Mr. John Watts");
        SubjectScore englishScore = new SubjectScore();
        englishScore.setScore(80);
        englishScore.setSubject("English");
        englishScore.setTeacher("Mrs. Mary Johnson");
        subjectScoreList.add(mathScore);
        subjectScoreList.add(englishScore);
        return subjectScoreList;
    }
}
